home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / Asm / Demos / Julia.s < prev    next >
Encoding:
Text File  |  1997-05-02  |  6.3 KB  |  330 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;JULIA 2
  3. ;-------
  4. ;A fractal generator, not orginally written by myself but now works with
  5. ;GMS.
  6.  
  7.     INCDIR    "INCLUDES:"
  8.     INCLUDE    "games/games_lib.i"
  9.     INCLUDE    "games/games.i"
  10.  
  11. CALL    MACRO
  12.     jsr    _LVO\1(a6)
  13.     ENDM
  14.  
  15.     SECTION    "Julia",CODE
  16.  
  17. ;==========================================================================;
  18. ;                             INITIALISE DEMO
  19. ;==========================================================================;
  20.  
  21.     STARTGMS
  22.  
  23. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  24.     move.l    GMSBase(pc),a6
  25.     lea    ScreenTags(pc),a0
  26.     CALL    ShowScreen
  27.     tst.l    d0
  28.     beq.s    Error_Screen
  29.  
  30.     bra.s    Julia
  31.  
  32. Exit:    move.l    GMSBase(pc),a6
  33.     lea    ScreenTags(pc),a0
  34.     CALL    DeleteScreen
  35. Error_Screen
  36.     MOVEM.L    (SP)+,A0-A6/D1-D7
  37.     moveq    #ERR_OK,d0
  38.     rts
  39.  
  40. ;==========================================================================;
  41. ;                                DRAW JULIA
  42. ;==========================================================================;
  43.  
  44. Julia:    lea    DataArea(pc),a5
  45.     move.l    #$fffffffe,(a5)+    ;a5 = $fffffffe+
  46.     move.l    #$80000014,(a5)+    ;a5 = mask & word per raster count
  47.  
  48. StartJulia:
  49.     move.l    GMSBase(pc),a6
  50.     move.l    Screen(pc),a0
  51.     moveq    #BUFFER1,d0
  52.     CALL    ClrScreen
  53.  
  54.     move.l    Screen(pc),a0
  55.     move.l    GS_MemPtr1(a0),a0
  56.     lea    JuliaData(pc),a6
  57.     move.l    (a6)+,(a5)    ;a5 = ?
  58. .JuliaFound
  59.     move.w    (a5),MValue    ;initial m
  60.     move.w    (a6),PixStep    ;pixel step
  61.     move.w    (a6)+,RastStep    ;raster step
  62.     move.l    (a6)+,C1C2    ;initial c1 and c2
  63.     move.w    #256,LinesLeft(a5)    ;vertical height
  64.     lea    256*40(a0),a1
  65.     lea    256*40(a1),a2
  66.     lea    256*40(a2),a3
  67.     lea    $04000000,a6    ;for magnitude test
  68.  
  69.     lea    256*40(a3),a4
  70.  
  71.     MOVE.L    A6,-(SP)
  72.     move.l    GMSBase(pc),a6
  73.     CALL    WaitVBL
  74.     MOVE.L    (SP)+,A6
  75.  
  76. PixelLoop:
  77.     move.w    (a5),d1    ;d1 = Initial X
  78.     move.w    InitialY(a5),d0    ;d0 = Initial Y
  79.     moveq    #30,d7    ;d7 = 30.
  80.     movem.w    C1C2(pc),d4-d5    ;MA : d4/d5 = C1/C2
  81.     move.w    d0,d2    ;d2 = Initial Y
  82.     move.w    d1,d3    ;d3 = Initial X
  83.     bra.s    CheckMagnitude
  84.  
  85. IterateJulia:
  86.     sub.l    d3,d2    ;x^2 - y^2
  87.     lsl.l    #4,d2    ;fix decimal point
  88.     swap    d2    ;...
  89.     add.w    d4,d2    ;x1 = x^2 - y^2 + c1
  90.  
  91.     move.w    d1,d3    ;y
  92.     muls    d0,d3    ;x * y
  93.     lsl.l    #5,d3    ;fix decimal point and multiply by 2
  94.     swap    d3    ;...
  95.     add.w    d5,d3    ;y1 = 2 * x * y + c2
  96.  
  97.     move.w    d2,d0    ;x = x1
  98.     move.w    d3,d1    ;y = y1
  99.  
  100. CheckMagnitude:
  101.     muls    d2,d2    ;x^2
  102.     muls    d3,d3    ;y^2
  103.     move.l    d2,d6
  104.     add.l    d3,d6    ;z = x^2 + y^2
  105.     cmp.l    a6,d6    ;escaped yet?
  106.     dbhi    d7,IterateJulia
  107.  
  108.     move.w    PixelMask(a5),d6
  109.     moveq    #0,d5
  110.     move.b    JumpTable+1(pc,d7.w),d5
  111.     jmp    JumpTable(pc,d5.w)
  112.  
  113. JumpTable:
  114.     dc.b    Plot00-JumpTable
  115.     dc.b    Plot31-JumpTable
  116.     dc.b    Plot30-JumpTable
  117.     dc.b    Plot29-JumpTable
  118.     dc.b    Plot28-JumpTable
  119.     dc.b    Plot27-JumpTable
  120.     dc.b    Plot26-JumpTable
  121.     dc.b    Plot25-JumpTable
  122.     dc.b    Plot24-JumpTable
  123.     dc.b    Plot23-JumpTable
  124.     dc.b    Plot22-JumpTable
  125.     dc.b    Plot21-JumpTable
  126.     dc.b    Plot20-JumpTable
  127.     dc.b    Plot19-JumpTable
  128.     dc.b    Plot18-JumpTable
  129.     dc.b    Plot01-JumpTable
  130.     dc.b    Plot16-JumpTable
  131.     dc.b    Plot15-JumpTable
  132.     dc.b    Plot14-JumpTable
  133.     dc.b    Plot13-JumpTable
  134.     dc.b    Plot12-JumpTable
  135.     dc.b    Plot11-JumpTable
  136.     dc.b    Plot10-JumpTable
  137.     dc.b    Plot09-JumpTable
  138.     dc.b    Plot08-JumpTable
  139.     dc.b    Plot07-JumpTable
  140.     dc.b    Plot06-JumpTable
  141.     dc.b    Plot05-JumpTable
  142.     dc.b    Plot04-JumpTable
  143.     dc.b    Plot03-JumpTable
  144.     dc.b    Plot02-JumpTable
  145.     dc.b    Plot17-JumpTable
  146.  
  147. Plot22:    or.w    d6,(a4)
  148.     or.w    d6,(a2)
  149.     or.w    d6,(a1)
  150.     bra.b    Plot00
  151.  
  152. Plot21:    or.w    d6,(a4)
  153.     or.w    d6,(a2)
  154.     or.w    d6,(a0)
  155.     bra.b    Plot00
  156.  
  157. Plot20:    or.w    d6,(a4)
  158.     or.w    d6,(a2)
  159.     bra.b    Plot00
  160.  
  161. Plot18:    or.w    d6,(a4)
  162.     or.w    d6,(a1)
  163.     bra.b    Plot00
  164.  
  165. Plot26:    or.w    d6,(a4)
  166. Plot10:    or.w    d6,(a3)
  167.     or.w    d6,(a1)
  168.     bra.b    Plot00
  169.  
  170. Plot23:    or.w    d6,(a4)
  171.     or.w    d6,(a2)
  172.     or.w    d6,(a1)
  173.     or.w    d6,(a0)
  174.     bra.b    Plot00
  175.  
  176. Plot19:    or.w    d6,(a4)
  177.     or.w    d6,(a1)
  178.     or.w    d6,(a0)
  179.     bra.b    Plot00
  180.  
  181. Plot27:    or.w    d6,(a4)
  182. Plot11:    or.w    d6,(a3)
  183.     or.w    d6,(a1)
  184.     or.w    d6,(a0)
  185.     bra.b    Plot00
  186.  
  187. Plot17:    or.w    d6,(a4)
  188.     or.w    d6,(a0)
  189.     bra.b    Plot00
  190.  
  191. Plot25:    or.w    d6,(a4)
  192. Plot09:    or.w    d6,(a3)
  193.     or.w    d6,(a0)
  194.     bra.b    Plot00
  195.  
  196. Plot29:    or.w    d6,(a4)
  197. Plot13:    or.w    d6,(a3)
  198. Plot05:    or.w    d6,(a2)
  199.     or.w    d6,(a0)
  200.     bra.b    Plot00
  201.  
  202. Plot16:    or.w    d6,(a4)
  203.     bra.b    Plot00
  204.  
  205. Plot24:    or.w    d6,(a4)
  206. Plot08:    or.w    d6,(a3)
  207.     bra.b    Plot00
  208.  
  209. Plot28:    or.w    d6,(a4)
  210. Plot12:    or.w    d6,(a3)
  211. Plot04:    or.w    d6,(a2)
  212.     bra.b    Plot00
  213.  
  214. Plot30:    or.w    d6,(a4)
  215. Plot14:    or.w    d6,(a3)
  216. Plot06:    or.w    d6,(a2)
  217. Plot02:    or.w    d6,(a1)
  218.     bra.b    Plot00
  219.  
  220. Plot31:    or.w    d6,(a4)
  221. Plot15:    or.w    d6,(a3)
  222. Plot07:    or.w    d6,(a2)
  223. Plot03:    or.w    d6,(a1)
  224. Plot01:    or.w    d6,(a0)
  225.  
  226. Plot00:    MOVE.L    D0,-(SP)
  227.     move.w    PixStep(pc),d0
  228.     add.w    d0,(a5)    ;pixel "step"
  229.     MOVE.L    (SP)+,D0
  230.  
  231.     ror.w    PixelMask(a5)    ;shift mask over
  232.     bpl.w    PixelLoop
  233.  
  234.     addq.w    #2,a0
  235.     addq.w    #2,a1
  236.     addq.w    #2,a2
  237.     addq.w    #2,a3
  238.     addq.w    #2,a4
  239.     subq.w    #1,WordsInRaster(a5)    ; subtract from word counter
  240.     bne.w    PixelLoop
  241.  
  242.     MOVE.L    A6,-(SP)
  243.     move.l    GMSBase(pc),a6
  244.     CALL    AutoSwitch
  245.     MOVE.L    (SP)+,A6
  246.  
  247.     btst.b    #6,$bfe001
  248.     beq    Exit
  249.  
  250.     move.w    #320/16,WordsInRaster(a5) ; words per raster
  251.     btst.b    #2,$dff016    ;new julia?
  252.     beq.b    NewJulia
  253.  
  254. RasterInit:
  255.     move.w    MValue(pc),(a5)    ;inital M value
  256. RasterAdd:
  257.     MOVE.L    D0,-(SP)
  258.     move.w    RastStep(pc),d0
  259.     add.w    d0,InitialY(a5)    ; raster "step"
  260.     MOVE.L    (SP)+,D0
  261.     subq.w    #1,LinesLeft(a5)
  262.     bne.w    PixelLoop
  263.  
  264. WaitMouse:
  265.     btst.b    #6,$bfe001
  266.     beq    Exit
  267.     btst.b    #2,$dff016
  268.     bne.b    WaitMouse
  269.  
  270. NewJulia:
  271.     btst.b    #2,$dff016
  272.     beq.b    NewJulia
  273.     bra.w    StartJulia
  274.  
  275. ;===========================================================================;
  276. ;                                  DATA
  277. ;===========================================================================;
  278.  
  279. MValue:    dc.w    0
  280. PixStep:
  281.     dc.w    0
  282. RastStep:
  283.     dc.w    0
  284. C1C2:    dc.l    0
  285.  
  286. ScreenTags:
  287.     dc.l    TAGS_GAMESCREEN
  288. Screen:    dc.l    0
  289.     dc.l    GSA_Palette,.palette
  290.     dc.l    GSA_ScrWidth,320
  291.     dc.l    GSA_ScrHeight,256
  292.     dc.l    GSA_Planes,5
  293.     dc.l    GSA_ScrType,PLANAR
  294.     dc.l    TAGEND
  295.  
  296. .palette
  297.     dc.l    $000000,$803010,$0000e0,$0000d0,$0000c0,$0000b0,$0000a0,$000090
  298.     dc.l    $000080,$000070,$100060,$200050,$300040,$400030,$500020,$601010
  299.     dc.l    $702000,$0000f0,$904020,$a05030,$b06040,$c07050,$d08060,$c09070
  300.     dc.l    $b0a080,$a090a0,$9080b0,$807090,$706070,$505050,$304030,$103010
  301.  
  302. JuliaData:
  303.     dc.l    $f800eb00
  304.     dc.w    $0018,$0100,$0ad0,$ec00
  305.  
  306.     dc.l    $fd21eeae
  307.     dc.w    $0225,$000d,$f420,$fd43
  308.  
  309.     dc.l    $ef000010
  310.     dc.w    $0600,$0100,$f226,$fd56
  311.  
  312.     dc.l    $0015ee00
  313.     dc.w    $fb40,$ede2,$f0b2,$001d
  314.  
  315.     dc.l    $05c0ff00
  316.     dc.w    $ef12,$e812,$001d,$f320
  317.     dc.l    0
  318.  
  319.  
  320.     rsset    -4
  321. PixelMask rs.w    1    ;mask to "OR" with bitplanes
  322. WordsInRaster rs.w 1    ;number of words left in current raster
  323. InitialX rs.w    1    ;inital x
  324. InitialY rs.w    1    ;inital y
  325. LinesLeft rs.w    1    ;number of lines left to draw
  326.  
  327.     dc.l    0
  328. DataArea:
  329.     ds.b    40
  330.